import { BaseProtocolStruct } from "../base/BaseProtocol";
import { NetDefine } from "../NetDefine";
import MsgAdapt from "../../MsgAdapt";

/** 玩家登录协议 */
export class UserLogin extends BaseProtocolStruct {
    static className: string = `UserLogin`;
    /** 协议号 */
    msgType: number = NetDefine.ProtocolID.Login;
    /** 登录类型 */
    loginType: number = NetDefine.eLoginType.Guest;
    /** 登录码 */
    key: string = ``; 

    encode(){
        MsgAdapt.writeBegin(this.msgType);
        MsgAdapt.writeNum(this.loginType);
        MsgAdapt.writeStr(this.key);
    }

    nick: string = ``;
    icon: string = ``;
    uface: number = 0;
    usex: number = 0;
    uvip: number = 0;
    uid: number = 0;
    decode() {
        MsgAdapt.readBegin();
        this.status = MsgAdapt.readNum();
        if (this.status == NetDefine.Response.OK) {
            this.uid = MsgAdapt.readNum();
            this.nick = MsgAdapt.readStr();
            this.icon = MsgAdapt.readStr();
            this.uface = MsgAdapt.readNum();
            this.usex = MsgAdapt.readNum();
            this.uvip = MsgAdapt.readNum();
        }
    }
}

/** 玩家重复登录协议 */
export class UserRelogin extends BaseProtocolStruct {
    static className: string = `UserRelogin`;
    msgType: number = NetDefine.ProtocolID.Relogin;
    encode(){}
    decode(){}
}

/** 玩家数据更新 */
export class UpdateUserInfo extends BaseProtocolStruct {
    static className: string = `UpdateUserInfo`;
    msgType: number = NetDefine.ProtocolID.UpdateUserInfo;
    nickName: string = ``;
    icon: string = null;
    country: string = `China`;
    province: string = ``
    city: string = ``;
    language: string = `zh_CN`;
    face: number = 0;
    sex: number = 0;
    vip: number = 0;
    
    encode(){
        console.log(`UpdateUserInfo`, this.msgType);
        MsgAdapt.writeBegin(this.msgType);
        MsgAdapt.writeStr(this.nickName);
        MsgAdapt.writeStr(this.icon);
        MsgAdapt.writeStr(this.country);
        MsgAdapt.writeStr(this.province);
        MsgAdapt.writeStr(this.city);
        MsgAdapt.writeStr(this.language);
        MsgAdapt.writeNum(this.face);
        MsgAdapt.writeNum(this.sex);
        MsgAdapt.writeNum(this.vip);
    }

    decode(){
        MsgAdapt.readBegin();
        this.status = MsgAdapt.readNum();
        if (this.status == NetDefine.Response.OK) {
            this.nickName = MsgAdapt.readStr();
            this.icon = MsgAdapt.readStr();
            this.country = MsgAdapt.readStr();
            this.province = MsgAdapt.readStr();
            this.city = MsgAdapt.readStr();
            this.language = MsgAdapt.readStr();
            this.face = MsgAdapt.readNum();
            this.sex = MsgAdapt.readNum();
            this.vip = MsgAdapt.readNum();
        }
    }
}
